package com.example.testdemo.demos.web.Controller;

import com.example.testdemo.demos.web.Config.JwtInfo;
import com.example.testdemo.demos.web.Config.Result;
import com.example.testdemo.demos.web.Config.ResultEnum;
import com.example.testdemo.demos.web.Entity.MenuItem;
import com.example.testdemo.demos.web.Service.JwtRedistService;
import com.example.testdemo.demos.web.Service.MenuItemService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;


@RestController
@RequestMapping("/api")
public class MenuItemController {

    @Resource
    private MenuItemService menuItemService;
    @Resource
    private JwtRedistService jwtRedistService;

    /**
     * 查询菜单接口
     * @param menu
     * @param token
     * @return
     */
    @PostMapping("/selMenu")
    public Result selMenuItem(@RequestBody MenuItem menu,@RequestHeader("token") String token){
        Result result =new Result();
        try {
            JwtInfo jwtInfo =new JwtInfo();
            if (!(token.isEmpty())){
                 jwtInfo =jwtRedistService.getUserInfo(token);
            }else {
                jwtInfo.setPass(false);
            }
            return menuItemService.getMenuItem(menu,jwtInfo);
        }catch (Exception e){
            result.setCode(ResultEnum.FORBIDDEN.getCode());
            result.setMsg(ResultEnum.FORBIDDEN.getData());
        }
        return result;
    }

}
